import * as formatMap from './formatter'

export function listToMap(list, keyField) {
  const result = {}
  if (list && list.length > 0)
    list.forEach((item) => {
      result[item[keyField]] = item
    })
  return result
}

export function getFormat(key) {
  return formatMap[key] || undefined
}

export function isBlank(value) {
  return value == undefined || value == null || value.trim() == ''
}

export function hasChildren(menu) {
  return menu?.children?.length > 0
}

export function isFolderMenu(menu) {
  return menu.type === 0
}

export function isLinkMenu(menu) {
  return menu.type === 1 && menu.linkFlag === 1
}

export function isMenu(menu) {
  return menu.type === 1 && menu.linkFlag === 0
}

export function hasIcon(menu) {
  return menu.icon && menu.icon !== ''
}

export function isHttp(url) {
  // console.log(url)
  return url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1
}
